﻿using System;
using System.Text;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;

namespace iSlideTools.LocalServer.Service
{
    public static class DataProtectionServer
    {
        public static string ToBase64String(this string str)
        {
            var encoding = new UTF8Encoding();
            var bytes = encoding.GetBytes(str);
            return Convert.ToBase64String(bytes);
        }


        public static string Hashing(this string password)
        {
            // generate a 128-bit salt using a secure PRNG
            var salt = new byte[128 / 8];
            // derive a 256-bit subkey (use HMACSHA1 with 10,000 iterations)
            var hashed = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                password,
                salt,
                KeyDerivationPrf.HMACSHA1,
                10000,
                256 / 8));
            return hashed;
        }
    }
}